package cn.zwk.excel;

import java.util.Objects;

/**
 * 解析后的列标识：包含列索引与表头名称（如果存在）。
 */
public final class ColumnIdentifier {
    private final int index; // 0-based
    private final String headerName; // 允许为 null

    public ColumnIdentifier(int index, String headerName) {
        this.index = index;
        this.headerName = headerName;
    }

    public int index() {
        return index;
    }

    public String headerName() {
        return headerName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ColumnIdentifier that = (ColumnIdentifier) o;
        return index == that.index && Objects.equals(headerName, that.headerName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(index, headerName);
    }

    @Override
    public String toString() {
        return "ColumnIdentifier{" +
            "index=" + index +
            (headerName == null ? "" : ", header='" + headerName + '\'' + '}');
    }
}

